package com.chw.controller;

import com.chw.common.ChwTS;
import com.chw.model.Imgs;
import com.chw.model.Shop;
import com.chw.model.vo.ShopVo;
import com.chw.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("shop")
public class ShopController {
    @Autowired
    private ShopService  shopService;
    @RequestMapping("addShop")
    public ChwTS addShop(Shop shop,String values,String imgs){
            try{
                shopService.addShop(shop,values,imgs) ;
                return ChwTS.success("");
            }catch (Exception e){
                return ChwTS.error(500,e.getMessage());
            }
    }
    @RequestMapping("queryShop")
    public ChwTS queryShop(ShopVo shop){
        try{

            return ChwTS.success(shopService.queryShop(shop));
        }catch (Exception e){
            return ChwTS.error(500,e.getMessage());
        }
    }
    @RequestMapping("delShop")
    public ChwTS delShop(Integer id){
        try{
            if (id==null){
                return ChwTS.error(400,"缺少参数");
            }
            shopService.delShop(id);
            return ChwTS.success("");
        }catch (Exception e){
            return ChwTS.error(500,e.getMessage());
        }
    }
    @RequestMapping("upShop")
    public ChwTS upShop(Shop shop){
        try{
            if (shop.getId()==null){
                return ChwTS.error(400,"缺少参数");
            }
            shopService.upShop(shop);
            return ChwTS.success("");
        }catch (Exception e){
            return ChwTS.error(500,e.getMessage());
        }
    }
    @RequestMapping("updateValuesByPid")
    public ChwTS updateValuesByPid(Integer pid ,String values){
        try{
            if (pid==null){
                return ChwTS.error(400,"缺少参数");
            }
            shopService.updateValuesByPid(pid,values);
            return ChwTS.success("");
        }catch (Exception e){
            return ChwTS.error(500,e.getMessage());
        }
    }


    //附图的查询
    @RequestMapping("queryImgs")
    public ChwTS queryImgs(Integer id){
        try{
            if (id==null){
                return ChwTS.error(400,"缺少参数");
            }

            return ChwTS.success(shopService.queryImgs(id));
        }catch (Exception e){
            return ChwTS.error(500,e.getMessage());
        }
    }
    //附图的修改
    @RequestMapping("upImgs")
    public ChwTS upImgs(String imgs,Integer pid,Integer id){
        try{
            if (pid==null|| id==null){
                return ChwTS.error(400,"缺少参数");
            }
            shopService.upImgs(imgs,pid,id);
            return ChwTS.success("");
        }catch (Exception e){
            return ChwTS.error(500,e.getMessage());
        }
    }
}
